package cn.hdu.liang.ch05;

/**
 * 强制未检查的Throwable转换为RuntimeException
 */
public class LaunderThrowable {

    /**
     * 强制未检查的Throwable转换为RuntimeException
     * 如果 Throwable 是 Error,就 throw,
     * 如果是 RuntimeException，那么就 return,
     * 否则就抛出 IllegalStateException
     */
    public static RuntimeException launderThrowable(Throwable t) {
        if(t instanceof RuntimeException)
            return (RuntimeException) t;
        else if(t instanceof Error)
            throw (Error) t;
        else
            throw new IllegalStateException("Not unchecked", t);
    }
}
